﻿//using JavaScriptEngineSwitcher.Core;
//using JavaScriptEngineSwitcher.Jint;
using JavaScriptEngineSwitcher.Core;
using Jint;

namespace Dot.Js
{
    public class JSBuild
    {
        public JSBuild()
        {

            //// 初始化 JsEngineSwitcher
            //JsEngineSwitcher.Initialize(new JintJsEngineFactory());

            //using (var jsEngine = new JintJsEngine())
            //{

            //}


            // 创建 JsEngine 实例
            IJsEngine jsEngine = JsEngineSwitcher.Current.CreateDefaultEngine();


            // dot.js 模板
            string dotJsTemplate = "var result = doT.template('Hello {{=it.name}}!');";
            jsEngine.Execute(dotJsTemplate);


            // 准备数据
            var data = new { name = "World" };
            // 将数据传递给 JavaScript 引擎
            jsEngine.SetVariableValue("it", data);
            // 执行模板替换
            jsEngine.Execute("var output = result(it);");
            // 获取替换后的结果
            string output = jsEngine.GetVariableValue<string>("output");
            Console.WriteLine(output);

        }
    }
}
